var app = getApp(),
  $ = require("../../utils/httpHelper.js"),
  WxNotificationCenter = require("../../WxNotificationCenter/WxNotificationCenter.js")//通知传参
Page({
  data: {
    height: '',
    width: '',
    currentcat: 0,
    catid:0,
    page:1,
    pagesize:6,
    category_list: [],
    good_list:[],
    totalpage:0,
    nomore:true,
    status:''
  },
  onShareAppMessage: function (res) {
    app.shareApp(res)
  },
  onLoad: function (option) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          height: res.windowHeight,
          width: res.windowWidth
        })
      }
    })
    if (!app.check_empty(option.status)){
      this.setData({
        status: option.status
      })
      $.httpPost("category_list", {status:this.data.status}, (data, err) => {
        this.setData({
          category_list: data.list
        })
      })

      var param = { status: this.data.status, catid: this.data.catid, page: this.data.page, pagesize: this.data.pagesize }
      $.httpPost("good_list", param, (data, err) => {
        this.setData({
          good_list: data.lists,
          totalpage: data.total_page
        })
      })
    }
    
  },
  leftmenu:function(e){
    //let index = e.currentTarget.dataset.index
    let id = e.currentTarget.dataset.id
    this.setData({
      currentcat : id,
      catid:id,
      good_list:[],
      page:1
    })
    var param = { status: this.data.status, catid: this.data.catid, page: this.data.page, pagesize: this.data.pagesize }
    $.httpPost("good_list", param, (data, err) => {
      this.setData({
        good_list: data.lists,
        totalpage:data.total_page
      })
    })
  },
  toinfo:function(e){
    let id = e.currentTarget.dataset.id
    let status = this.data.status
    wx.navigateTo({
      url: '/pages/goods/goods_detail_buy?id='+id+'&status='+status,
    })
  },
  tocar: function () {
    wx.navigateTo({
      url: '/pages/car/car',
    })
  },
  //滑动到底部 上拉加载
  scrollBottom: function () {
    this.data.page++
    if (this.data.page > this.data.totalpage) {
      console.log('dfd')
      wx.showToast({
        title: '没有更多啦',
        duration: 2000
      })      
      this.setData({
        nomore: false
      })
    } else {
      console.log('fjlkdsa')
      var param = { status: this.data.status, catid: this.data.catid, page: this.data.page, pagesize: this.data.pagesize }
      $.httpPost("good_list", param, (data, err) => {
        let arr = this.data.good_list;
        for (let item of data.lists) {
          arr.push(item);
        }
        this.setData({
          good_list: arr
        })
      })
      
    }

  },

});